package com.daqian.mall.service;

import com.daqian.mall.entity.ModuleGoodsClassify;
import com.daqian.mall.entity.ModuleGoodsClassify;
import com.daqian.mall.mapper.ModuleGoodsClassifyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class ClassifyService {

    @Resource
    private ModuleGoodsClassifyMapper moduleGoodsClassifyMapper;

    /**
     * 根据id获取详情
     *
     * @param id
     * @return
     */
    public ModuleGoodsClassify getById(Long id) {
        return moduleGoodsClassifyMapper.getById(id);
    }

    /**
     * 获取所有分类
     *
     * @return
     */
    public List<ModuleGoodsClassify> listAllClassify() {
        return moduleGoodsClassifyMapper.selectAll();
    }

    /**
     * 新增分类
     *
     * @return
     */
    public void saveClassify(ModuleGoodsClassify entity) {
        entity.setId(null);
        moduleGoodsClassifyMapper.insertSelective(entity);
    }

    /**
     * 修改分类
     *
     * @return
     */
    public void updateClassify(ModuleGoodsClassify entity) {
        moduleGoodsClassifyMapper.updateByPrimaryKeySelective(entity);
    }

    /**
     * 删除单个分类
     *
     * @return
     */
    public void deleteClassify(Long id) {
        moduleGoodsClassifyMapper.deleteByPrimaryKey(id);
    }

    /**
     * 删除多个分类
     *
     * @return
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteClassify(Long[] ids) {
        for (Long id : ids) {
            moduleGoodsClassifyMapper.deleteByPrimaryKey(id);
        }
    }

}


